﻿
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UI;


public partial class XObjBase : MonoBehaviour
{
    //孵化器逻辑
    [NonSerialized]
    public XIncubator incubator;
    [NonSerialized]
    public string key2Incubate;

    //不允许调用GameObject.Destroy(gameObject);直接销毁我，否则会增加生产逻辑代码复杂度
    [ContextMenu("XDestroy")]
    public void XDestroy()
    {
        if (incubator != null)
        {
            this.Recycle();
            incubator.Enqueue(key2Incubate, this.gameObject);//归还给孵化器
        }
        else
        {
            this.Recycle();
            GameObject.Destroy(this.gameObject);
        }
    }

    protected void OnDestroyIncubator()
    {
        XInstanceMgr.ReleaseInstance(this.gameObject);//自己销毁
    }

    public void Reuse()
    {
        OnReuse();
    }

    //订阅、退阅消息，不能放这里。放OnEnable。这里只做一些表现重置
    protected virtual void OnReuse()
    {

    }

    public void Recycle()
    {
        OnRecycle();
    }

    //订阅、退阅消息，不能放这里。放OnDisable。这里只做一些表现重置
    protected virtual void OnRecycle()
    {

    }
}
